using UnityEngine;
using System.Collections;

public class Highscore : MonoBehaviour {
	//public Game game;
	public static string highscorePos;
	public static int temp;
	public static int score;
	public static float t=0f;
	public static float blinkspd=0.2f;

	void Start()
	{
		//game=GetComponent<GUI>();
	}

	public static void SaveHighScore()
	{
		score=CoinController.coinCount;
		
		for(int i=1; i<=5; i++) //for top 5 highscores
		{
			if(PlayerPrefs.GetInt("highscorePos"+i)<score) //if current score is in top 5
			{
				temp=PlayerPrefs.GetInt("highscorePos"+i); //store the old highscore in temp varible to shift it down
				PlayerPrefs.SetInt("highscorePos"+i,score); //store the currentscore to highscores
				//if(i<5) //do this for shifting scores down
				//{
				//	int j=i+1;
				//	PlayerPrefs.SetInt("highscorePos"+j,temp);
				//}
				score=temp;
				return;
			}
		}
	}

	public void OnGUI()
	{
		//if(CoinController.coinCount)
		{
			bool plrfound=false;
			
			t+=Time.deltaTime;
			if(t>blinkspd)
				t=0f;
			
			for(int i=1; i<=5; i++)
			{
				if(CoinController.coinCount==PlayerPrefs.GetInt("highscorePos"+i) && plrfound==false)
				{
				
					if(t<blinkspd/2)
						GUI.Box(new Rect(Screen.width/2-75, Screen.height/2-112+32*i, 150, 24), "");
					else
						GUI.Box(new Rect(Screen.width/2-75, Screen.height/2-112+32*i, 150, 24), ""+PlayerPrefs.GetInt("highscorePos"+i));
					
					plrfound=true;
				}
				else
					GUI.Box(new Rect(Screen.width/2-75, Screen.height/2-112+32*i, 150, 24), ""+PlayerPrefs.GetInt("highscorePos"+i));
			}
		}
	}
}

